<?php
	include $_SERVER['DOCUMENT_ROOT']."/include/function.php";
	
	//Retrieve post data
	$username = $_POST["username"];
	$password = md5($_POST["password"]);
	
	connect_db(); //Connect to database

	$sql = "select * from users where username='$username' and password='$password' ";
	//echo $sql;
	$result = mysql_query($sql);
	$num = mysql_num_rows($result);
	//echo $num;
	if($num > 0)
	{
		$row = mysql_fetch_array($result);
		
		session_start();
		$_SESSION["id"] = $row["u_id"];
		$_SESSION["role"] = "customer";
		$_SESSION["username"] = $row["username"];
		$_SESSION["email"] = $row["email"];
		$_SESSION["address"] = $row["address"];
		$_SESSION["name"] = $row["name"];
		$_SESSION["surname"] = $row["surname"];
		$_SESSION["title"] = $row["title"];
		$_SESSION["picture_type"] = $row["picture_type"];
		//May not use
		$_SESSION["password"] = $row["password"];
		$_SESSION["status"] = $row["status"];
		$_SESSION["sex"] = $row["sex"];
		$_SESSION["personal"] = $row["personal"];
		
		echo "success";
	}else{
		echo "fail";
	}
?>